package logic

import (
	"box/models"
	"context"
	"fmt"

	"box/boxrpc/boxrpc"
	"box/boxrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopShowLogic {
	return &ShopShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *ShopShowLogic) ShopShow(in *boxrpc.ShopShowRequest) (*boxrpc.ShopShowResponse, error) {
	// todo: add your logic here and delete this line

	var shop models.Shop
	models.DB.Debug().Where("id = ?", in.ShopId).Find(&shop)
	if shop.ID == 0 {
		return nil, fmt.Errorf("当前商品不存在无法查询")
	}

	return &boxrpc.ShopShowResponse{
		Name:      shop.Name,
		Profile:   shop.Profile,
		Weight:    float32(shop.Weight),
		Price:     float32(shop.Price),
		ClassName: shop.ClassName,
		ShopId:    int64(shop.ID),
	}, nil
}
